package com.ssy.lingxi.common.constant.product;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;

/**
 * 商品定价方式
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/29
 */
public enum PriceTypeEnum {

    Cash(1, "现货价格"),
    Consult(2, "价格需要询价"),
    Score(3, "积分兑换商品"),
    Gift(4, "赠品");

    private Integer code;
    private String name;

    PriceTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return LanguageHolder.getName(this.getClass(), this.code);
    }

    public static String getNameByCode(Integer code) {
        PriceTypeEnum typeEnum = Arrays.stream(PriceTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return null == typeEnum ? "" : LanguageHolder.getName(PriceTypeEnum.class, typeEnum.getCode());
    }

    public static Boolean contains(Integer code) {
        return Arrays.stream(PriceTypeEnum.values()).anyMatch(e -> e.getCode().equals(code));
    }
}
